# Maintainer: Ray Donnelly <mingwandroid@gmail.com>
# Upstream Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Upstream Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>

_realname=frei0r-plugins
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.3
pkgrel=3
pkgdesc='Minimalistic plugin API for video effects (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://frei0r.dyne.org/"
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-cairo"
             $([[ ${CARCH} == i686 ]] || echo \
               "${MINGW_PACKAGE_PREFIX}-gavl" \
               "${MINGW_PACKAGE_PREFIX}-opencv"))
optdepends=("${MINGW_PACKAGE_PREFIX}-cairo: cairoaffineblend, cairoblend, cairogradient and cairoimagegrid plugins")
if [[ ${CARCH} != i686 ]]; then
  optdepends+=("${MINGW_PACKAGE_PREFIX}-gavl: rgbparade, scale0tilt and vectorscope plugins"
               "${MINGW_PACKAGE_PREFIX}-opencv: facebl0r and facedetect plugins")
fi
source=("https://github.com/dyne/frei0r/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('aeeefe3a9b44761b2cf110017d2b1dfa2ceeb873da96d283ba5157380c5d0ce5')
validpgpkeys=('6113D89CA825C5CEDD02C87273B35DA54ACB7D10') # Denis Roio (Jaromil)

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  local -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  if [[ ${CARCH} == i686 ]]; then
    _extra_config+=("-DWITHOUT_OPENCV=ON" "-DWITHOUT_GAVL=ON")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe -Wno-dev \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${_extra_config[@]}" \
    ../frei0r-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  # make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
